package com.gxuwz.medical.domain.policy;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.gxuwz.medical.database.DbUtil;

public class Policy {
	private int year = Integer.parseInt(new Timestamp(new Date().getTime()).toString().substring(0, 4));;
	private double topline;//封顶线
	private double ratio;//比例
	public boolean hasSet=false;
	public Policy(){
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try{
			conn = new DbUtil().getConn();
			stmt= conn.createStatement();
			String sql = "select * from policy where year="+this.year+"";
			rs = stmt.executeQuery(sql);
			while(rs.next()){
				this.hasSet = true;
				this.topline = rs.getDouble("topline");
				this.ratio = rs.getDouble("ratio");
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}
	public Policy(double topline, double ratio){
		this.topline = topline;
		this.ratio = ratio;
	}
	public void add() throws SQLException{
		DbUtil db = new DbUtil();
		String sql ="insert into policy(year,topline,ratio) values('"+getYear()+"','"+getTopline()+"','"+getRatio()+"')";
		db.executeUpdate(sql);
	}
	public void del() throws SQLException{
		DbUtil db = new DbUtil();
		String sql ="delete from policy where year = '"+year+"'";
		db.executeUpdate(sql);
	}

	public void edit() throws SQLException{
		DbUtil db = new DbUtil();
		String sql ="update policy set topline="+getTopline()+",ratio="+getRatio()+" where year="+getYear()+"";
		db.executeUpdate(sql);
	}
	
	
	public int getYear() {
		return year;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public double getTopline() {
		return topline;
	}
	public void setTopline(double topline) {
		this.topline = topline;
	}
	public double getRatio() {
		return ratio;
	}
	public void setRatio(double ratio) {
		this.ratio = ratio;
	}
	

	
}
